﻿using System;

using Moe.ECamel.Client.Controllers;
using Moe.ECamel.Client.WinForms.Common;
using Moe.ECamel.Common.Entities;

namespace Moe.ECamel.Client.WinForms.Controls
{
	public partial class CustomerControl : ECamelUserControl
	{
		public CustomerControl()
		{
			InitializeComponent();
		}
		public CustomerControl(Customer customer)
			: this()
		{
			Initialize(customer);
		}

		public void Initialize(Customer customer)
		{
			this.CustomerDetailsControl.Initialize(customer, DetailsMode.View);
			this.SubscriptionListControl.Initialize(new SubscriptionsController(customer.CustomerId));
			this.SubscriptionListControl.SubscriptionAdded += SubscriptionListControl_SubscriptionAdded;
			this.ItemSearchControl.Initialize(new ItemsController(customer));
			this.RentalListControl.Initialize(new RentalsController(customer.CustomerId));
			this.PaymentsListControl.Initialize(new PaymentsController(customer.CustomerId));
			this.MailMessageListControl.Initialize(new MailMessagesController(customer.UserId));
		}

		public void CancelEdit()
		{
			this.CustomerDetailsControl.CancelEdit();
		}

		private void SubscriptionListControl_SubscriptionAdded(object sender, EventArgs e)
		{
			this.CustomerDetailsControl.RefreshBinding();
		}

		private void CustomerDetailsTabPage_Enter(object sender, EventArgs e)
		{
		}
		private void CustomerSubscriptionsTabPage_Enter(object sender, EventArgs e)
		{
			this.SubscriptionListControl.RefreshView();
		}
		private void ItemSearchTabPage_Enter(object sender, EventArgs e)
		{
		}
		private void CustomerRentalsTabPage_Enter(object sender, EventArgs e)
		{
			this.RentalListControl.RefreshView();
		}
		private void CustomerMailMessagesTabPage_Enter(object sender, EventArgs e)
		{
			this.MailMessageListControl.RefreshView();
		}

		private void CustomerPaymentsTabPage_Enter(object sender, EventArgs e)
		{
			this.PaymentsListControl.RefreshView();
		}
	}
}
